# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libotr
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.1.1
pkgrel=2
pkgdesc="Off-the-Record Messaging Library and Toolkit (mingw-w64)"
arch=('any')
url="https://www.cypherpunks.ca/otr/"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-libgcrypt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=(https://otr.cypherpunks.ca/${_realname}-${pkgver}.tar.gz{,.asc}
        '002-libotr-no-undefined.patch'
        '003-fix-symlinks.patch')
sha256sums=('8b3b182424251067a952fb4e6c7b95a21e644fbb27fbd5f8af2b2ed87ca419f5'
            'SKIP'
            '4e7f9cc91ec623687d26d26e2f5e735df0de6bd0ab429f30d55f35a54be628e6'
            'f91be0fea077a562d39e50bb53d9b7dcca87bdb9303ee4fe63dc4be047947c9b')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/002-libotr-no-undefined.patch
  patch -p1 -i ${srcdir}/003-fix-symlinks.patch

  autoreconf -fi
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --mandir=${MINGW_PREFIX}/share/man

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -j1 DESTDIR="${pkgdir}" install
}
